#
# make into all sub directory
#

TEST_DIR=test

ifndef _USER_DEFINE_DIRS_
ALL_SUB_DIRS_WITHOUT_TEST=$(shell ls|grep -v '\<$(TEST_DIR)\>'|grep -v Makefile)
else
ALL_SUB_DIRS_WITHOUT_TEST=$(_USER_DEFINE_DIRS_)
endif

ALL_SUB_DIRS=$(shell ls|grep -v Makefile)

##################################
#
# Make all sub directories
# Won't make test by default
#
##################################
all:
ifdef PRE_CMD
	$(PRE_CMD)
endif
	@for x in $(ALL_SUB_DIRS_WITHOUT_TEST);		\
	do								\
		if [[ -e $$x/Makefile || -e $$x/makefile ]];	\
		then						\
		$(PUSHD) $$x;				\
		$(MAKE) ;					\
		$(POPD);	 				\
		else						\
		$(ECHO) "SubDir Warning: Makefile not found in $$x";\
		fi							\
	done						
ifdef LIBS_TO_CP
	$(MKDIR) -p $(HBLIB_PATH)
	@for x in $(LIBS_TO_CP);			\
		do							\
		$(CP) $$x	$(HBLIB_PATH);	\
		done						
endif

clean:
	${RM} $(MAKE_LOG_FILE)
	@for x in $(ALL_SUB_DIRS);		\
	do								\
		if [[ -e $$x/Makefile || -e $$x/makefile ]];	\
		then						\
		$(PUSHD) $$x;				\
		$(MAKE) clean;				\
		$(POPD);	 				\
		fi							\
	done
ifdef POST_CLEAN_CMD
	$(POST_CLEAN_CMD)
endif

test:all
	$(PUSHD) $(TEST_DIR);			\
	$(MAKE);						\
	$(POPD);	 					

$(SPLINT_TARGET):
	@for x in $(ALL_SUB_DIRS_WITHOUT_TEST);		\
	do								\
		if [[ -e $$x/Makefile || -e $$x/makefile ]];	\
		then						\
		$(PUSHD) $$x;				\
		$(MAKE) $(SPLINT_TARGET);					\
		$(POPD);	 				\
		else						\
		$(ECHO) "SubDir Warning: Makefile not found in $$x";\
		fi							\
	done						
include $(BUILD_MK)

# vim:noet:sw=4:ts=4

